﻿Imports System.IO
Imports System.Data
Imports System.Resources

Public Class frmDataObsExport

    'La propriété public odatasource permet de mettre en mémoire la DataTable
    Dim x As Integer
    Dim DateNom As String
    Dim FichNom As String
    Private rm As New ResourceManager(GetType(frmDataObsExport))


    Private Sub btnSauverXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSauverXML.Click
        Dim StrT As String = ""
        'Previens quand la grid est vide
        If frmDataObsTable.dgGrid2.CurrentRowIndex = -1 Then
            MessageBox.Show(DirectCast(My.Resources.Images.alertNoData, String), "Pocket eRelevé")
            Exit Sub
            'Lorsque la Grid est nom vide, la sauvegarde dans mes Documents en fichiers .xml
        Else
            Try
                StrT = FormMain.oListObs.ExportListObsTOXML()
                Export("", StrT, "Fichiers XML(xml)|*.nsml|Tous les fichiers|*.*")
                MsgBox(DirectCast(My.Resources.Images.AlertSaveOk, String), MsgBoxStyle.Information, "Pocket eRelevé")
            Catch ex As Exception
                MsgBox(DirectCast(My.Resources.Images.errorOnSave, String) & " : " & ex.Message, MsgBoxStyle.Critical, "Pocket eRelevé")
            End Try
        End If
    End Sub

    Private Sub btnSauverGPX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSauverGPX.Click

        Dim StrT As String = ""

        'Previens quand la grid est vide
        If frmDataObsTable.dgGrid2.CurrentRowIndex = -1 Then
            MessageBox.Show(DirectCast(My.Resources.Images.alertNoData, String), "Pocket eRelevé")
            Exit Sub
            'Lorsque la Grid est nom vide, la sauvegarde dans mes Documents en fichiers .xml
        Else
            Try
                StrT = ExportObsXMLToGPX(FormMain.oListObs.ExportListObsTOXML())
                Export("", StrT, "Fichiers GPX(gpx)|*.gpx|Tous les fichiers|*.*")
                MsgBox(DirectCast(My.Resources.Images.AlertSaveOk, String), MsgBoxStyle.Information, "Pocket eRelevé")
            Catch ex As Exception
                MsgBox(DirectCast(My.Resources.Images.errorOnSave, String) & " : " & ex.Message, MsgBoxStyle.Critical, "Pocket eRelevé")
            End Try

        End If
    End Sub

    Private Sub btnSauverkml_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSauverkml.Click

        'déclaration des strings qui contiendrons chaques balises de kml
        Dim strT As String

        If frmDataObsTable.dgGrid2.CurrentRowIndex = -1 Then
            MessageBox.Show(DirectCast(My.Resources.Images.alertNoData, String), "Pocket eRelevé")
            Exit Sub
        Else
            Try
                strT = ExportObsXMLToKML(FormMain.oListObs.ExportListObsTOXML())
                Export("", strT, "Fichiers KML(kml)|*.kml|Tous les fichiers|*.*")
                MsgBox(DirectCast(My.Resources.Images.AlertSaveOk, String), MsgBoxStyle.Information, "Pocket eRelevé")
            Catch ex As Exception
                MsgBox(DirectCast(My.Resources.Images.errorOnSave, String) & " : " & ex.Message, MsgBoxStyle.Critical, "Pocket eRelevé")
            End Try
        End If


    End Sub

    Private Sub btnSauverCSV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSauverCSV.Click

        Dim StrT As String = String.Empty

        If frmDataObsTable.dgGrid2.CurrentRowIndex = -1 Then
            MessageBox.Show(DirectCast(My.Resources.Images.alertNoData, String), "Pocket eRelevé")
            Exit Sub
        Else
            Try
                StrT = ExportObsXMLToCSV(FormMain.oListObs.ExportListObsTOXML())
                Export("", StrT, "Fichiers CSV(csv)|*.csv|Tous les fichiers|*.*")
                MsgBox(DirectCast(My.Resources.Images.AlertSaveOk, String), MsgBoxStyle.Information, "Pocket eRelevé")
            Catch ex As Exception
                MsgBox("Sauvegarde impossible: " & ex.Message, MsgBoxStyle.Critical, "Pocket eRelevé")
            End Try
        End If


    End Sub

    Private Sub btnRetour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetour.Click
        Me.Hide()
        frmDataObsTable.Show()
    End Sub

    Private Sub btnMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMenu.Click
        Me.Hide()
        FormMain.Show()
    End Sub

End Class